<?php
	if($_REQUEST['level'] > 0)
	{ $level = $_REQUEST['level']; }
	$position = 1;
	if($_REQUEST['position'] != '') 
	{ $position = $_REQUEST['position']; }
		
	if($_REQUEST['item'] > 0)
	{ $item['id'] = $_REQUEST['item']; }
	if($item['id'] > 0)
	{ 
		$item 			= getMenuTypeAdmin($item['id'], $level, $position); 
		$incats 		= getInHFBCats($item['id'], CSS_TYPE_ID);
		
		if($item['position'] == 0)
		{ $posadd = '.first'; }
		if($item['position'] == 2)
		{ $posadd = '.last'; }
		if($item['level'] > 0)
		{ $levadd = '.level_'.$item['level']; }
		else
		{
			if($item['type'] == 4)
			{ $levadd = '.level_'.$item['level']; }
		}
	}
	switch ($_POST['action'])
	{
		case 'new_item':
			if($_POST['name'] != '')
			{ addMenuType($_POST['name']); }
			$i=0;
			if($_POST['menutype_id'])
			{
				foreach($_POST['menutype_id'] as $id)
				{
					updateMenuType($id, $_POST['menutype_name'][$i], $_POST['menutype_type'][$i]);
					$i++;
				}
			}
			if($_POST['load_css'] > 0)
			{ reloadHFBTypeCss($_POST['load_css']); }
			if($_POST['activate'] > 0)
			{ setTableActive($_POST['activate'], 'com_menu', 1); }
			if($_POST['deactivate'] > 0)
			{ setTableActive($_POST['deactivate'], 'com_menu', 0); }
			if($_POST['delete_menutype'] > 0)
			{ deleteMenuType($_POST['delete_menutype']); } 
			break;
		case 'editor':
			if($item['id'] > 0)
			{
				if($_POST['add_level'] > 0)
				{ addMenuLevel($item['id'], $item['level']);}
				if($_POST['delete_level'] > 0)
				{ deleteMenuLevel($item['id'], $_POST['delete_level']);}
				
				if($_POST['add_first'] > 0)
				{ addMenuFirst($item['id'], $item['level']);}
				if($_POST['add_last'] > 0)
				{ addMenuLast($item['id'], $item['level']);}
				
				if(($item['level'] == 0) && ($item['position'] == 1))
				{ updateMenuType($item['id'], $_POST['name'], $_POST['type']); }
				
				uploadMenuTypeImages($item['id'], $item['level'], $item['position'], $imagenames);
				
				foreach($imagenames as $imagename)
				{
					if(($_POST['delete_'.$imagename] == "1") && ($item[$imagename] != ""))
					{ deleteMenuTypeImage($item['id'], $item['level'], $item['position'], $imagename, $item[$imagename]); }
				}
			
				if($_POST['add_to_cat'] > 0)
				{ addItemToCat($item['id'], CSS_TYPE_ID, $_POST['add_to_cat']);}
				if($_POST['rem_from_cat'] > 0)
				{ removeItemFromCat($item['id'], CSS_TYPE_ID, $_POST['rem_from_cat']);}
				
				if($posadd == '')
				{ updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'], trim($_POST['cm_div'])); }
				
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul', trim($_POST['ul']));
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li', trim($_POST['ul_li']));
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li ul', trim($_POST['ul_li_ul']));
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li ul li', trim($_POST['ul_li_ul_li']));
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li:hover ul', trim($_POST['ul_li_h_ul']));
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li:hover ul li', trim($_POST['ul_li_h_ul_li']));
				
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.'', trim($_POST['cm_a'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.':hover', trim($_POST['cm_a_h'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.'.active', trim($_POST['cm_a_active'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.'.active:hover', trim($_POST['cm_a_active_hover'])); 
				
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.' h2', trim($_POST['cm_h2'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.':hover h2', trim($_POST['cm_h2_h'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.'.active h2', trim($_POST['cm_h2_active'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.'.active:hover h2', trim($_POST['cm_h2_active_hover'])); 
				
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.' h2 span', trim($_POST['cm_span'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.':hover h2 span', trim($_POST['cm_span_h'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.'.active h2 span', trim($_POST['cm_span_active'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.'.active:hover h2 span', trim($_POST['cm_span_active_hover']));
				
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.' h2 span div', trim($_POST['cm_span_div'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.':hover h2 span div', trim($_POST['cm_span_div_h'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.'.active h2 span div', trim($_POST['cm_span_div_active'])); 
				updateCss(CSS_TYPE_ID,$item['id'],'div.com_menus div.cm_'.$item['id'].' ul li a'.$levadd.$posadd.'.active:hover h2 span div', trim($_POST['cm_span_div_active_hover'])); 
				reloadHFBTypeCss(CSS_TYPE_ID);
			}
			break;
	}
	if($_REQUEST['cat'] > 0)
	{ $menu_types = getMenuTypes($_REQUEST['cat']); }
	else
	{ $menu_types = getMenuTypes(); }
	if($item['id'] > 0)
	{ 
		$item 	= getMenuTypeAdmin($item['id'], $level, $position); 
		$incats = getInHFBCats($item['id'], CSS_TYPE_ID);
		if($item['position'] == 0)
		{ $posadd = '.first'; }
		if($item['position'] == 2)
		{ $posadd = '.last'; }
		if($item['level'] > 0)
		{ $levadd = '.level_'.$item['level']; }
		else
		{
			if($item['type'] == 4)
			{ $levadd = '.level_'.$item['level']; }
		}
	}
?>